<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>仪表数据管理</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/dist.css">
</head>
<body>
<h1>仪表数据管理</h1>
<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">日期范围</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="dateRange">
        </div>
    </div>
    <div class="layui-inline">
        <button class="layui-btn layui-btn-primary">看本月</button>
    </div>
    <div class="layui-inline" id="control">
        <div class="layui-btn-group">
            <button class="layui-btn" onclick="addRow(table)">增加</button>
            <button class="layui-btn" onclick="changeRows(chosedRows)">编辑</button>
            <button class="layui-btn layui-btn-danger" onclick="delRows(chosedRows)">删除</button>
        </div>
        <button class="layui-btn layui-btn-normal" onclick="confirm(submit_args)">确认更改</button>
    </div>
</div>
<table class="layui-table">
    <thead>
    <tr id="table_head">
        <td class="layui-form" id="choseAll">
            <input type="checkbox" lay-skin="primary">
        </td>
        <td>仪表编号</td>
        <td>住户姓名</td>
        <td>物业地址</td>
        <td>年份</td>
        <td>月份</td>
        <!--<td>上月数据</td>-->
        <!--<td>本月数据</td>-->
        <td>本月用量</td>
        <td>单价</td>
        <td>本月费用</td>
        <td>上月抄表日期</td>
        <td>本月交费日期</td>
        <td>办理人</td>
    </tr>
    </thead>
    <tbody id="show">
    </tbody>
</table>
<button onclick="getNext(-5)">上一页</button>
<button onclick="getNext(5)">下一页</button>
</body>
<script src="/layui/layui.js"></script>
<script src="/js/init.js"></script>
<script src="/js/fetch.js"></script>
<script src="/js/checkTable.js"></script>
<script src="/js/admin/submit.js"></script>
<script src="/js/admin/addRow.js"></script>
<script>
    let page_no = 0;
    let table = document.getElementById('show');
    let head = document.getElementById('table_head');
    let order = checkTable(table, head);
    let identity = 'admin';//TODO: 身份验证
    let submit_args = [];
    let admin_table = [];

    if (identity !== 'admin') {
        order.shift();
        document.getElementById('control').style.display = 'none';
        document.getElementById('choseAll').style.display = 'none';
    } else {
        admin_table.push({
            type: 'checkbox',
            content: 'chose',
            isNode: true
        }, {
            tip: '自动生成，推荐不填',
            content: order[1],
            beSubmit: 'waterid',
            isPrimary: true//删除的唯一标识字段
        }, {
            tip: '长度最长20位',
            content: order[2],
            required: true,
            beSubmit: 'ownerName'
        }, {
            tip: '长度最长20位',
            content: order[3],
            required: true,
            beSubmit: 'serverAddress'
        }, {
            content: function (spans) {
                return spans[0] + '-' + spans[1]
            },
            type: 'month',
            col_span: 2,
            span_group: [4, 5],
            required: true,
            beSubmit: 'handleDate'
        }, {
            type: 'double',
            default_value: 0,
            content: order[6],
            beSubmit: 'dosage'
        }, {
            type: 'double',
            default_value: 0,
            content: order[7],
            beSubmit: 'price'
        }, {
            type: 'functions',
            dependent: [order[6], order[7]],
            content: order[8],
            method: function (item) {
                return item[order[6]].value * item[order[7]].value;
            }
        }, {
            type: 'date',
            content: order[9],
            beSubmit: 'lastMonthRecord'
        }, {
            type: 'date',
            content: order[10],
            beSubmit: 'monthPayed'
        }, {
            content: order[11],
            beSubmit: 'handleGuy'
        });
    }

    getNext(0, table);

    let chosedRows = [];
</script>
</html>